[Objective-C] Primitive question, (void) init method.

Posted by user354289 on Stack Overflow See other posts from Stack Overflow or by user354289
Published on 2010-05-31T04:31:34Z Indexed on 2010/05/31 4:32 UTC
Read the original article Hit count: 327

Filed under:
|
|

Hi, I have a question in Objective-C. I'm using init method Apple recommended style.

- (id)initMyClass: (int)a
{
   if (self = [super init])
   {
       // a...
   }
   return self;
}

Init method returns own object pointer. Then, if the object will not be refered from any objects, can empty return method(void) be better?

- (void)initMyClass: (int)a
{
  if ([super init] != nil)
  {
      // a...
  }
}

I want to know about that, if init method doesn't return self, what problem will occur?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about return